import qs from 'qs';
export default {
  test(VueInstance){
    console.log(VueInstance.$Message);
    VueInstance.$Message.info("12312");
  },
  test2(VueInstance){
    console.log(VueInstance.$router);
    VueInstance.$router.push({name:"Test"});
  },
  get:function(VueInstance, url, data) {
    console.log("发送url");
    console.log("发送data");
    return VueInstance.$http({
      method: "get",
      url: url,
      params: data
    });
  },
  post:function(VueInstance, url, data) {
    console.log("发送url");
    console.log("发送data");
   /* axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8';
    axios.interceptors.request.use((config) => {  //POST传参序列化
      if(config.method  === 'post'){
        config.data = qs.stringify(config.data);
      }
      return config;
    },(error) =>{
      alert("错误的传参");
      return Promise.reject(error);
    });*/
    /*VueInstance.$http.interceptors.request.use((config) => {  //POST传参序列化
      if(config.method  === 'post'){
        config.data = qs.stringify(config.data);
      }
      return config;
    },(error) =>{
      alert("错误的传参");
      return Promise.reject(error);
    });*/
    return VueInstance.$http({
      method: "post",
      url: url,
      data: data,
      headers:{'Content-Type':'application/x-www-form-urlencoded;charset=UTF-8'},
      transformRequest: [function (data) {
        // 对 data 进行任意转换处理
        data = qs.stringify(data);
        return data;
      }],
    });
  }
}
